package cn.hwadee.muying.service;

import cn.hwadee.muying.entity.Consult;
import cn.hwadee.muying.mapper.ConsultMapper;
import cn.hwadee.muying.commons.base.BaseService;
import org.springframework.stereotype.Service;
import cn.hwadee.muying.entity.User;
import cn.hwadee.muying.commons.page.MyPage;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * <p>
 * 咨询 服务实现类
 * </p>
 *
 * @author Mankind
 * @since 2018-08-13
 */
@Service
public class ConsultService extends BaseService<ConsultMapper, Consult> {

    @Autowired
    private ConsultMapper consultMapper;
    @Autowired
    private UserService userService;

    public MyPage<Consult> list(MyPage<Consult> page, User cUser) throws Exception{
        List<Consult> consults = consultMapper.list(page,cUser);
        for(Consult consult:consults){
            if(consult.getUserId()!=null){
                User user=userService.selectById(consult.getUserId());
                consult.setUsername(user.getUsername());
            }
        }
        page.setRecords(consults);
        return page;
    }

}
